package demo1;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 涛
 * Date: 2023-10-26
 * Time: 13:09
 */
class TestDemo {
    public void func(){
        System.out.println("func()");
    }
}
@FunctionalInterface
interface NoParameterNoReturn1 {
    void test();
}
public class Test2 {
    public static void main(String[] args) {
        int a = 100;
        NoParameterNoReturn noParameterNoReturn = () -> {
            //a = 99;err
            System.out.println("捕获变量："+a);};
        noParameterNoReturn.test();
    }
    public static void main2(String[] args) {
        int a = 100;
        //匿名内部类变量的捕获
        TestDemo testDemo = new TestDemo() {
            //a = 99;err
            public void func() {
                System.out.println("我是内部类，且重写了func这个方法！");
                System.out.println("捕获了a：" + a);
            }
        };
        testDemo.func();
    }
    public static void main1(String[] args) {
        //匿名内部类的简单使用
        TestDemo testDemo = new TestDemo() {
            public void func() {
                System.out.println("我是内部类，且重写了func这个方法！");
            }
        };
        testDemo.func();
    }
}
